package com.zzj.service;

import com.zzj.bean.AccountBean;
import com.zzj.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(
        isolation = Isolation.READ_COMMITTED,
        transactionManager = "transactionManager",
        propagation = Propagation.REQUIRED
)
public class AccountServiceImpl implements  AccountService {

    @Autowired
    private AccountDao dao;

    @Override
    public boolean add(AccountBean accountBean) {
        return dao.add(accountBean) > 0 ? true : false;
    }

    @Override
    public boolean del(int aid) {
        return dao.del(aid) > 0 ? true : false;
    }

    @Override
    public boolean update(AccountBean accountBean) {
        return dao.update(accountBean) > 0 ? true : false;
    }

    @Override
    public List<AccountBean> findAll() {
        return dao.findAll();
    }

    @Override
    public AccountBean findById(int aid) {
        return dao.findById(aid);
    }

    @Override
    public boolean transformMoneyById(int from, int to, double money) {
        dao.transformMoneyById(from,0-money);
        dao.transformMoneyById(to,money);
        return true;
    }
}
